﻿using QBWeb.Models;
using QBWeb.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace QBWeb.BLL
{
    public class DBBll
    {
        private readonly QBDbContext db = new QBDbContext();
        /// <summary>
        /// 题库
        /// </summary>
        public List<Problem> ProblemDB;

        // 初始化数据库
        public DBBll()
        {
            ProblemDB = new List<Problem>();
            var question = db.QuestionTbs.ToList();
            Problem model;
            Random rand = new Random();
            List<int> Points;

            foreach(var item in question)
            {
                model = new Problem();
                model.ID = item.Id;
                model.Difficulty = item.QuestLevel / 5.0;
                model.Type = item.QuestTypeTbId;
                if (model.Type == 1)
                {
                    model.Score = 2;
                }else if(model.Type == 2)
                {
                    model.Score = 2;
                }else if(model.Type == 3)
                {
                    model.Score = 2;
                }else if(model.Type == 4)
                {
                    model.Score = 5;
                }else if(model.Type == 5)//问答题分数为难度系数*10
                {
                    model.Score = model.Difficulty > 0.3 ? (int)(double.Parse(model.Difficulty.ToString("f1")) * 10) : 3;
                }

                Points = new List<int>();
                //每题属于1个知识点
                Points.Add(item.SmallKnowModuleTbId==null?0:(int)item.SmallKnowModuleTbId);
                model.Points = Points;

                ProblemDB.Add(model);
            }
        }
    }
}